function debounce(func, wait, immediate) {
  let timeOut, result
  const debounce = function () {
    if (timeOut) { clearTimeout(timeOut) }
    if (immediate) {
      //立即执行
      let callNow = !timeOut
      timeOut = setTimeout(function () {
        timeOut = null
      }, wait);
      console.log(!timeOut);
      if (callNow) {
        result = func.apply(this, arguments)
      }
    } else {
      timeOut = setTimeout(function () {
        result = func.apply(this, arguments)
      }, wait);
    }
    return result
  }
  debounce.cancle = function () {
    clearTimeout(timeOut)
    timeOut = null
  }
  return debounce
}